package org.mch.func.db.mysql;

import java.awt.BorderLayout;
import java.awt.Font;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.border.EmptyBorder;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.mch.biz.ui.FuncEvent;
import org.mch.biz.ui.FuncPanel;
import org.mch.swingm.core.MButton;
import org.mch.swingm.ext.METextChooser;
import org.mch.swingm.ext.METextField;

/**
 * 描述：MySQL密码修改；<BR/>
 *
 * @author mchweb.net；<BR/>
 *
 */
public class MySQLPWPanel extends FuncPanel {
	private static final long serialVersionUID = 1L;

	private JPanel panel_conn;
	private MButton btn_killMysql;
	private JSplitPane splitPane;
	private JScrollPane scrollPane;
	private RSyntaxTextArea text_log;
	private METextChooser text_mysqlPath;
	private MButton btn_startMysql;
	private METextField text_mysqlPass;
	private MButton btn_modifyPass;

	public MySQLPWPanel() {

		setBounds(100, 100, 624, 471);
		this.setBorder(new EmptyBorder(5, 5, 5, 5));
		this.setLayout(new BorderLayout(0, 0));
		setLayout(new BorderLayout(0, 0));
		add(getSplitPane());
	}

	public JPanel getPanel_conn() {
		if (this.panel_conn == null) {
			this.panel_conn = new JPanel();
			panel_conn.setLayout(null);
			panel_conn.add(getBtn_killMysql());
			panel_conn.add(getText_mysqlPath());
			panel_conn.add(getBtn_startMysql());
			panel_conn.add(getText_mysqlPass());
			panel_conn.add(getBtn_modifyPass());
		}

		return this.panel_conn;
	}

	@Override
	protected FuncEvent createEvent() {
		return new MySQLPWEvent(this);
	}

	public MButton getBtn_killMysql() {
		if (btn_killMysql == null) {
			btn_killMysql = new MButton("关闭MySQL");
			btn_killMysql.setBounds(509, 54, 93, 34);
			btn_killMysql.addActionListener(getEvent());
		}
		return btn_killMysql;
	}

	public JSplitPane getSplitPane() {
		if (splitPane == null) {
			splitPane = new JSplitPane();
			splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
			splitPane.setLeftComponent(getPanel_conn());
			JPanel buttonPane = new JPanel();
			splitPane.setRightComponent(buttonPane);
			buttonPane.setLayout(new BorderLayout(0, 0));
			buttonPane.add(getScrollPane(), BorderLayout.CENTER);
			splitPane.setDividerLocation(300);
		}
		return splitPane;
	}

	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getText_log());
		}
		return scrollPane;
	}

	public RSyntaxTextArea getText_log() {
		if (text_log == null) {
			text_log = new RSyntaxTextArea();
			text_log.setFont(new Font("宋体", Font.PLAIN, 13));
		}
		return text_log;
	}

	public METextChooser getText_mysqlPath() {
		if (text_mysqlPath == null) {
			text_mysqlPath = new METextChooser("目录：", METextChooser.SELECT_FOLDER);
			text_mysqlPath.getComponent().setText("E:\\ZL\\mysql-5.5.56-winx64");
			text_mysqlPath.setToolTipText("请选择MySQL根目录！");
			text_mysqlPath.setFont(new Font("宋体", Font.PLAIN, 12));
			text_mysqlPath.setBounds(10, 10, 592, 34);
		}
		return text_mysqlPath;
	}

	public MButton getBtn_startMysql() {
		if (btn_startMysql == null) {
			btn_startMysql = new MButton("关闭MySQL");
			btn_startMysql.setToolTipText("跳过权限检查启动mysql");
			btn_startMysql.setText("启动MySQL");
			btn_startMysql.setBounds(509, 98, 93, 34);
			btn_startMysql.addActionListener(getEvent());
		}
		return btn_startMysql;
	}

	public METextField getText_mysqlPass() {
		if (text_mysqlPass == null) {
			text_mysqlPass = new METextField();
			text_mysqlPass.getLabel().setText("MySQL新密码：");
			text_mysqlPass.setFont(new Font("宋体", Font.PLAIN, 12));
			text_mysqlPass.setBounds(10, 48, 276, 34);
		}
		return text_mysqlPass;
	}

	public MButton getBtn_modifyPass() {
		if (btn_modifyPass == null) {
			btn_modifyPass = new MButton("关闭MySQL");
			btn_modifyPass.setToolTipText("修改指定密码");
			btn_modifyPass.setText("修改密码");
			btn_modifyPass.setBounds(509, 142, 93, 34);
			btn_modifyPass.addActionListener(getEvent());
		}
		return btn_modifyPass;
	}
}
